package com.lifo.utils.queue.hfgooddescriptionqueue;

import com.lifo.good.bean.model.HfGoodDescription;
import com.lifo.good.service.SearchHfGoodDescriptionService;
import com.lifo.utils.queue.HuiFvQueue;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2018/5/17 0017.
 */
@Slf4j
@Component
public class ConsumerHfGoodDescription {

    @Autowired
    private SearchHfGoodDescriptionService searchHfGoodDescriptionService;


    void cleanHfGoodDescription() throws InterruptedException {
        if ( HuiFvQueue.newInstance().arrayBlockingQueue.size() > 0) {
            try {
                // produceHfGoodDescription.run();
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            HfGoodDescription hfGoodDescription = (HfGoodDescription)HuiFvQueue.newInstance().arrayBlockingQueue.take();
            log.debug("开始清洗商品,线程名是==>{},获取到的商品id是==>{}", Thread.currentThread().getName(), hfGoodDescription.getHfUid());
            String all = hfGoodDescription.getGoodInfo();
            String one = all.replaceAll("src=\"//img.alicdn.com/tps/i4/T10B2IXb4cXXcHmcPq-85-85.gif\"", "");
            String two = one.replaceAll("data-ks-lazyload", "src");
           /* Document pageSource = Jsoup.parse(hfGoodDescription.getGoodInfo());
            pageSource.*/
            // log.debug("清洗后的详情数据为==>{}",two);
            searchHfGoodDescriptionService.updateHfGoodDescriptionByHfUid(hfGoodDescription.getHfUid(), two);
          //  boolean removeOk = HuiFvQueue.newInstance().list.remove(hfGoodDescription);
            log.debug("线程==>{},是否删除list中的商品成功==>{}", Thread.currentThread().getName(), HuiFvQueue.newInstance().arrayBlockingQueue.size());
        }
    }
}
